Skip to content

Conversation

@Jszigeti
Copy link
Contributor

Problem

When using infinite lists or paginated lists with bulk selection, a bug caused duplicate record IDs in the selection array in specific scenarios.

  • Individual record selection worked fine
  • But when selecting records individually, then clicking the page header checkbox to select all visible records, the already selected records were added again to the selection array.

This was caused by an operator precedence error in the filter logic within SelectPageCheckbox.tsx. When isRowSelectable was undefined (the default case), the boolean expression was incorrectly evaluated, causing already selected items to bypass the duplicate check.


Solution

  • Fixed the filter logic in SelectPageCheckbox.tsx:
    • Corrected operator precedence in the boolean expression
    • Ensures the duplicate check (!selectedIds.includes(record.id)) is always respected
    • Maintains backward compatibility with existing isRowSelectable behavior

Added unit tests in DataTable.spec.tsx
Added E2E tests in list.cy.js

Both confirm correct behavior for:

  • Selecting individuals then using page checkbox (no duplicates)
  • Alternating check/uncheck/recheck (no duplicates)

How To Test

  1. Go to any list view with bulk selection enabled.
  2. Select 2-3 records individually by clicking their checkboxes.
  3. Click the page header checkbox to select all visible records.
  4. Expected result: Selection count equals total visible records (no duplicates).
  5. Run tests:
    • make test - Unit tests: 2594 passed
    • make test-e2e - E2E tests: 101 passed
      All tests pass successfully.

Additional Checks

  • The PR targets master for a bugfix
  • The PR includes unit tests (DataTable.spec.tsx)
  • The PR includes E2E tests (list.cy.js)
  • No documentation change required (fixes existing behavior)
  • No story update required (visual behavior unchanged)

Notes

  • Root cause: Operator precedence bug in filter expression (!selectedIds.includes(record.id) && isRowSelectable ? isRowSelectable(record) : true incorrectly evaluated when isRowSelectable is undefined).
  • No breaking changes.
  • Fixes issue affecting both infinite lists and paginated lists.
  • A couple of unrelated tests occasionally fail on master (confirmed unrelated to this change).

I'm happy to adjust anything if needed 👍

Copy link
Contributor

@slax57 slax57 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, and great PR, thanks!

@slax57 slax57 added this to the 5.13.2 milestone Nov 17, 2025
@slax57 slax57 merged commit f9409aa into marmelab:master Nov 17, 2025
21 of 24 checks passed
@slax57 slax57 changed the title Fix: Duplicate selections when using page checkbox Fix <DataTable> may duplicate ids in its selection state Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants